package com.webchat.admin.service;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.exception.BusinessException;
import com.webchat.domain.vo.request.CreateAccountRequestVO;
import com.webchat.domain.vo.request.CreateRobotRequestVO;
import com.webchat.domain.vo.response.UserBaseResponseInfoVO;
import com.webchat.rmi.user.UserServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class AccountManagementService {


    @Autowired
    private UserServiceClient userServiceClient;

    /**
     * 分页查询账号信息
     *
     * @param userId
     * @param roleCode
     * @param userName
     * @param mobile
     * @param pageNo
     * @param pageSize
     * @return
     */
    public APIPageResponseBean<UserBaseResponseInfoVO> page(String userId, Integer roleCode, String userName, String mobile, Integer pageNo, Integer pageSize) {

        return userServiceClient.page(userId, roleCode, userName, mobile, pageNo, pageSize);
    }

    /**
     * 账号搜索
     *
     * @param query
     * @param size
     * @return
     */
    public List<UserBaseResponseInfoVO> suggest(String query, Integer size) {

        return null;
    }


    /**
     * 创建机器人
     *
     * 复用用户信息表，账号角色为 ROBOT
     */
    public void createRobot(CreateRobotRequestVO requestPram) {
        APIResponseBean apiResponseBean = userServiceClient.createRobot(requestPram);
        if (APIResponseBeanUtil.isOk(apiResponseBean)) {
            return;
        }
        throw new BusinessException(apiResponseBean.getMsg());
    }

    /**
     * 创建公众号
     *
     * 复用用户信息表，账号角色为 PUBLIC_ACCOUNT
     */
    public void createPublicAccount(CreateAccountRequestVO requestVO) {
        APIResponseBean apiResponseBean = userServiceClient.createPublicAccount(requestVO);
        if (APIResponseBeanUtil.isOk(apiResponseBean)) {
            return;
        }
        throw new BusinessException(apiResponseBean.getMsg());
    }

    /**
     * 创建服务号
     *
     * 复用用户信息表，账号角色为 PUBLIC_ACCOUNT
     */
    public void createServerAccount(CreateAccountRequestVO requestVO) {
        APIResponseBean apiResponseBean = userServiceClient.createServerAccount(requestVO);
        if (APIResponseBeanUtil.isOk(apiResponseBean)) {
            return;
        }
        throw new BusinessException(apiResponseBean.getMsg());
    }

}
